//
//  MCGameRecordViewController.m
//  TLYL
//
//  Created by miaocai on 2017/7/10.
//  Copyright © 2017年 TLYL01. All rights reserved.
//

#import "MCGameRecordViewController.h"
#import "MCGameRecordTableViewCell.h"
#import "MCGameRecordDetailViewController.h"
#import "MCGameRecordMineFilterView.h"

@interface MCGameRecordViewController ()<UITableViewDelegate,UITableViewDataSource,UIScrollViewDelegate>


@property (nonatomic,weak) UITableView *tableView;
@property (nonatomic,strong) NSMutableArray *tableViewDataArray;
@property (nonatomic,weak) MCGameRecordMineFilterView *filterView;

@end





@implementation MCGameRecordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"游戏记录";
    [self addNavRightBtn];
    [self setUpUI];
    [self loadDataAndShow];
    
}


- (void)addNavRightBtn {
    
    UIButton *btn = [[UIButton alloc] init];
    [btn setImage:[UIImage imageNamed:@"kefu"] forState:UIControlStateNormal];
    [btn setTitle:@"全部" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont systemFontOfSize:14.0f];
    btn.frame = CGRectMake(0, 0, MC_REALVALUE(44), MC_REALVALUE(44));
    [btn addTarget:self action:@selector(allBtnClick:) forControlEvents:UIControlEventTouchDown];
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
    self.navigationItem.rightBarButtonItem = rightItem;
}

- (void)setUpUI{
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.view.backgroundColor = RGB(239, 239, 239);
    UIScrollView *baseScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 128 + 44, G_SCREENWIDTH, G_SCREENHEIGHT - 128 - 44)];
    [self.view addSubview:baseScrollView];
    baseScrollView.contentSize = CGSizeMake(G_SCREENWIDTH * 4, G_SCREENHEIGHT - 128 - 44);
    baseScrollView.pagingEnabled = YES;
    /**tabView 创建*/
    for (NSInteger i = 0; i<4; i++) {
        UITableView *tab = [[UITableView alloc] initWithFrame:CGRectMake(i * G_SCREENWIDTH, 0, G_SCREENWIDTH, G_SCREENHEIGHT - 128 - 44) style:UITableViewStylePlain];
        [baseScrollView addSubview:tab];
        baseScrollView.delegate = self;
        tab.delegate = self;
        tab.dataSource = self;
        self.tableView = tab;
        self.tableView.backgroundColor=RGB(240, 240, 240);
        self.tableView.estimatedRowHeight = MC_REALVALUE(90);
        self.tableView.rowHeight = 116;
        [self.tableView registerClass:[MCGameRecordTableViewCell class] forCellReuseIdentifier:@"MCGameRecordTableViewCell"];
    }

    MCGameRecordMineFilterView *filterView = [[MCGameRecordMineFilterView alloc] initWithFrame:CGRectMake(0, 64, G_SCREENWIDTH, 108)];
    self.filterView = filterView;
    filterView.gameRecFilterBtnClickBlock = ^(int index){
        [UIView animateWithDuration:0.25 animations:^{
            baseScrollView.contentOffset = CGPointMake(index * G_SCREENWIDTH, 0);
        }];
        
        
    };
    [self.view addSubview:filterView];
}
- (void)allBtnClick:(UIButton *)btn{
    
    
    
}

- (void)loadDataAndShow{

}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    int index = scrollView.contentOffset.x/G_SCREENWIDTH;
    [self.filterView changeBtnStatus:index];
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 10;//self.tableViewDataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    MCGameRecordTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MCGameRecordTableViewCell"];
//    cell.dataSource = self.tableViewDataArray[indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    MCGameRecordDetailViewController *vc = [[MCGameRecordDetailViewController alloc] init];
    //    vc.dataSorce = self.tableViewDataArray[indexPath.row];
    [self.navigationController pushViewController:vc animated:YES];
}
- (NSMutableArray *)tableViewDataArray{
    if (_tableViewDataArray == nil) {
        _tableViewDataArray = [NSMutableArray array];
    }
    return _tableViewDataArray;
}



@end
